<?php

class controller_user_control_panel extends controller
{


    // 修改用户资料
    public function edit()
    {
        $user = bone::get_user();
        if ($user->guest) exit('没有权限');
        
        $template = $this->get_template();
        $template->set_title('修改用户资料');
        $template->set('user', $user);
        $template->display();
    }

    // 修改用户资料
    public function ajax_edit_save()
    {
        $name = post('name', '');
        
        $model = $this->get_model();
        if ($model->edit($name))
        {
            $this->set_ajax('status', 0);
            $this->set_ajax('description', '您的资料已保存');
            $this->ajax();
        }
        else
        {
            $this->set_ajax('status', 1);
            $this->set_ajax('description', $model->get_error());
            $this->ajax();
        }
    }

    // 修改用户资料
    public function reset_password()
    {
        $user = bone::get_user();
        if ($user->guest) exit('没有权限');
        
        $template = $this->get_template();
        $template->set_title('重设密码');
        $template->set('user', $user);
        $template->display();
    }

    // 修改用户资料
    public function ajax_reset_password_save()
    {
        $password = post('password', '');
        $confirm_password = post('confirm_password', '');
        
        if ($password != $confirm_password)
        {
            $this->set_ajax('status', 1);
            $this->set_ajax('description', '两次输入的密码不一致');
            $this->ajax();
        }
        
        $model = $this->get_model();
        if ($model->reset_password($password))
        {
            $description = '重设密码成功， 下次您可以使用新密码登陆了。';
            $this->set_ajax('status', 0);
            $this->set_ajax('description', $description);
            $this->ajax();
        }
        else
        {
            $this->set_ajax('status', 2);
            $this->set_ajax('description', $model->get_error());
            $this->ajax();
        }
    
    }


}

?>